package com.neuedu.his5.config;

import com.neuedu.his5.tools.LocalDateFormatter;
import com.neuedu.his5.mvc.LoginInterceptor;
import com.neuedu.his5.tools.StringToLocalDateConverter;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Override
    public void addFormatters(FormatterRegistry registry) {
        registry.addConverter(new StringToLocalDateConverter());
        registry.addFormatter(new LocalDateFormatter());

        // register a interceptor for user login
        // registry.addInterceptor(new UserLoginInterceptor());
    }


    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        // 1. 添加自定义拦截器
        registry.addInterceptor(new LoginInterceptor())
                // 2. 配置要拦截的路径（/** 表示拦截所有请求）
                .addPathPatterns("/**")
                // 3. 配置放行的路径（比如登录接口、静态资源，避免拦截后无法登录）
                .excludePathPatterns("/his/login", "/static/**", "/error");
    }



}